package org.tao.lightningmq.broker.config;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author lht
 * @date 2025/1/3 - 20:32
 * @description: 线程池配置
 */
public class CommonThreadPoolConfig {

    //专门用于将topic配置异步刷盘使用
    private static final ThreadPoolExecutor refreshMqTopicExecutor = new ThreadPoolExecutor(1,
            1,
            30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), r -> {
        Thread thread = new Thread(r);
        thread.setName("refresh-mq-topic-config");
        return thread;
    });

    //专门用于将各个消费者消费进度刷新到磁盘中
    private static final ThreadPoolExecutor refreshConsumeQueueOffsetExecutor = new ThreadPoolExecutor(1,
            1,
            30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), r -> {
        Thread thread = new Thread(r);
        thread.setName("refresh-eagle-mq-topic-config");
        return thread;
    });

    public static void setRefreshMqTopicTask(Runnable task) {
        refreshMqTopicExecutor.execute(task);
    }

    public static void setRefreshConsumeQueueOffsetTask(Runnable task) {
        refreshConsumeQueueOffsetExecutor.execute(task);
    }

}
